{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "noticed-format",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/remove-nth-node-from-end-of-list/\n",
    "\n",
    "\n",
    "Runtime: 36 ms, faster than 52.17% of Python3 online submissions for Remove Nth Node From End of List.\n",
    "Memory Usage: 14.4 MB, less than 18.54% of Python3 online submissions for Remove Nth Node From End of List.\n",
    "\n",
    "\n",
    "```python\n",
    "# Definition for singly-linked list.\n",
    "# class ListNode:\n",
    "#     def __init__(self, val=0, next=None):\n",
    "#         self.val = val\n",
    "#         self.next = next\n",
    "class Solution:\n",
    "    def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:\n",
    "        #7:08\n",
    "        l = []\n",
    "        node = head\n",
    "        while node:\n",
    "            l.append(node.val)\n",
    "            node = node.next\n",
    "        del l[-n]\n",
    "        \n",
    "        if len(l) == 0:\n",
    "            return None\n",
    "        \n",
    "        new_head = ListNode(val=l[0])\n",
    "        node = new_head\n",
    "        for i, v in enumerate(l[1:]):\n",
    "            if i != len(l) - 1:\n",
    "                node.next = ListNode(val=l[1+i])\n",
    "                node = node.next\n",
    "        return new_head\n",
    "        #7:27\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "right-probe",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
